package com.wantong.jianpu.fragments.main;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.wantong.jianpu.BR;
import com.wantong.jianpu.R;
import com.wantong.jianpu.base.BaseXFragment;
import com.wantong.jianpu.beans.TabBean;
import com.wantong.jianpu.databinding.FragmentHomeBinding;
import com.wantong.jianpu.databinding.FragmentMessageBinding;
import com.wantong.jianpu.viewmodels.HomeViewModel;
import com.wantong.jianpu.viewmodels.MessageViewModel;

import java.util.ArrayList;

/**
 * @author PACY
 * @date 2022/4/1
 * description: 首页
 */
public class MessageFragment extends BaseXFragment<FragmentMessageBinding, MessageViewModel> {
    private ArrayList<CustomTabEntity> tabs = new ArrayList<>();
    public static MessageFragment newInstance(String title) {

        Bundle args = new Bundle();
        args.putString("title", title);
        MessageFragment fragment = new MessageFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_message;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        setStateLayout(binding.state);
        binding.swipeRefresh.setOnRefreshListener(() -> {
            viewModel.loadData(true);
        });

        viewModel.refreshEvent.observe(this, aBoolean -> {
            binding.swipeRefresh.setRefreshing(aBoolean);
        });
        initTab();
    }

    private void initTab() {
        tabs.add(new TabBean("待处理"));
        tabs.add(new TabBean("全部"));
        binding.tabLayout.setTabData(tabs);
        binding.tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if(position==0){
                    viewModel.setTypeRequest("0");
                }else{
                    viewModel.setTypeRequest("3");
                }

            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }
}
